﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Web.UI.WebControls;

namespace Module.Core.Common
{
    public class ClsCheckBox
    {
        public static int tinMoiNhat= 1;
        public static int tinNoiBat = 2;
        public static int tinTieuDiem = 4;
        
        public static int menuTop = 1;
        public static int menuLeft = 2;
        public static int menuRight = 4;
        public static int menuBottom = 8;
        public static int menuRss = 16;
        public static int menuWap = 32;        

        public static int nhacHotNhat = 1;
        public static int nhacMoiNhat = 2;

        public static int Viettel = 4;
        public static int Vinaphone = 8;
        public static int Mobifone = 16;
        public static int Vietnamobile = 32;
        public static int EVNtelecom = 64;
        public static int Sfone = 128;
        public static int Beeline = 256;

        public static int videoNoiBat = 1;
        public static int videoMoiNhat = 2;

        public static int hienThiTrangChu = 1;


        public static int SanPhamNoiBat = 1;
        public static int SanPhamHot = 2;
        public static int SanPhamMoiNhat =4;
        public static int SanPhamGiamGia = 8;

        public static int Cao = 1;
        public static int TrungBinh = 2;
        public static int Thap = 4;

        public static int MienPhi = 1;
        public static int ThuPhi = 2;
      

        
        public static bool Check(int CheckStatus, int CurrentStatus)
        {
            int _Temp = CurrentStatus & CheckStatus;
            if (_Temp != CheckStatus)
                return false;
            return true;
        }
        public static int BinToInt(string binaryNumber)// Convert bit sang số nguyên
        {
            int multiplier = 1;
            int i;
            int converted = 0;
            for (i = 0; i <= binaryNumber.Length - 1; i++)
            {
                int t = System.Convert.ToInt16(binaryNumber[i].ToString());
                converted = converted + (t * multiplier);
                multiplier = multiplier * 2;
            }
            return converted;
        }

        public static int ReturnStatusCheck(CheckBox[] CheckBox)// Trả về 1 dãy bit
        {
            string ValueCheck = "";
            for (int i = 0; i < CheckBox.Length; i++)
            {
                if (CheckBox[i].Checked == true)
                    ValueCheck = ValueCheck + "1";
                else
                    ValueCheck = ValueCheck + "0";
            }
            return Convert.ToInt32(BinToInt(ValueCheck));
        }

        public static bool SelectChecked(int Role, int CheckRole, CheckBox[] CheckBox)//Trả về True khi CheckBox được Checked
        {
            bool KQ = false;
            for (int i = 0; i < CheckBox.Length; i++)
            {
                if (Check(Role, CheckRole) == true)
                    return true;
                else
                    return false;
            }
            return KQ;
        }
    }
}
